# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
import pymysql

class BilibiliPipeline:
    def open_spider(self,spider):
        self.con = pymysql.connect(host='10.30.59.136', port=3306, user='root', password='123456', database='wdr',
                                   charset='utf8')
        #self.cur = self.con.cursor()
    def close_spider(self,spider):
        self.con.close()
    def process_item(self, item, spider):
        self.cur = self.con.cursor()
        self.cur.execute(
            'insert into bili (name,upname,kan,dan,shou,ying,fen,zan,time,lei) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',
            [item['name'], item['upname'], item['kan'], item['dan'], item['shou'], item['ying'], item['fen'],
             item['zan'], item['time'], item['lei']])
        self.cur = self.con.commit()

        return item
